#include <REGX52.H>
#include "OneWire.h"

#define DS18B20_SKIP_ROM			0xCC
#define DS18B20_CONVERT_T			0x44
#define DS18B20_Read_S				0xBE

/**
  * @brief  开始温度变换
  * @param  无
  * @retval 无
  */
void DS18B20_ConvertT()
{
	OneWire_Init();
	OneWire_SendByte(DS18B20_SKIP_ROM);
	OneWire_SendByte(DS18B20_CONVERT_T);
}

/**
  * @brief  读取温度
  * @param  无
  * @retval 温度值
  */
float DS18B20_ReadT()
{
	unsigned char TLSB,TMSB;
	int Temp;
	float T;
	
	OneWire_Init();
	OneWire_SendByte(DS18B20_SKIP_ROM);	
	OneWire_SendByte(DS18B20_Read_S);
	TLSB = OneWire_ReceiveByte();
	TMSB = OneWire_ReceiveByte();	
	Temp = (TMSB<<8)|TLSB;
	T = Temp/16.0; //相当于右移四位
	return T;
}